/*
 *    Copyright 2022 jacky4631 shen ji email:121659050@qq.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.dataoke.shoppingguide.app773026.activity.detail.base;

import static android.widget.Toast.LENGTH_SHORT;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.dataoke.shoppingguide.app773026.R;
import com.dataoke.shoppingguide.app773026.util.StatusBarUtils;
import com.dataoke.shoppingguide.app773026.util.ToastUtil;
import com.jaeger.library.StatusBarUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 *
 * @Author: shen ji
 * @Date: 2022/3/15
 * @Email: 121659050@qq.com
 * @Wechat: jacky4631
 */
public abstract class BaseDetailActivity extends AppCompatActivity {

    public Context context;
    public Toast toast;
    protected Unbinder unbinder;


    protected abstract int getLayoutId();

    protected abstract void initView();

    protected abstract void addListener();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusBar();
        if (getLayoutId() != 0) {
            setContentView(getLayoutId());
        }
        unbinder = ButterKnife.bind(this);
        context = this;


        initView();
        addListener();


    }

    protected void setStatusBar() {

//        //设置状态栏颜色;
        StatusBarUtil.setColorForSwipeBack(this,
                getResources().getColor(R.color.white), 0);
          //暗色
        StatusBarUtils.StatusBarLightMode(this, StatusBarUtils.StatusBarLightMode(this));

    }

    public void setStatusBar(View view) {
        if (view == null) {
            return;
        }
        ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, StatusBarUtils.getStatusBarHeight(context));
        view.setLayoutParams(params);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (unbinder != null) {
            unbinder.unbind();
        }

    }


    protected void setClipboard(String text, String tip) {
        ClipboardManager clipboard = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE);

        if (clipboard != null) {
            clipboard.setPrimaryClip(ClipData.newPlainText(null, text));//参数一：标签，可为空，参数二：要复制到剪贴板的文本
            ToastUtil.show(getApplicationContext(), tip, LENGTH_SHORT);
        }
    }
}
